#![allow(dead_code)]

struct TypeAnnotationLrn {}

impl TypeAnnotationLrn {
    pub fn hello() {
        println!("Type annotation learning!");
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    #[allow(unused_variables)]
    #[allow(unused_assignments)]
    #[allow(clippy::useless_vec)]
    fn show_type() {
        let mut var1 = 5;
        let var2 = 5.6_f64;
        let var3 = &5;
        let var4 = &var1;

        // [T] 胖指针
        let mut arr1 = [1, 2, 3];
        let arr2 = &[1, 2, 3];
        let arr3 = [[1, 2, 3], [4, 5, 6]];
        let arr4: &[i32];
        let arr5: [i32; 3];

        // &mut [i32] 是数组元素可变
        let arr6: &mut [i32] = &mut arr1;
        arr6[0] = 8;
        // mut arr7 是arr7可变,可以被赋其他值
        let mut arr7: &[i32] = &[1, 2, 3];
        arr7 = arr2;

        // 类型匹配,不知道有什么用
        let arr8: &mut [&mut i32] = &mut [&mut 1, &mut 2, &mut 3];
        arr8[0] = &mut 11;

        let arr9 = &mut &mut [1, 2, 3, 4];

        let vec1 = vec![1, 2, 3];
        let vec2 = &vec![1, 2, 3];
        let vec3 = vec![&1, &2, &3];
        let vec4 = vec![vec![1, 2, 3], vec![4, 5, 6]];
        let vec5 = vec![&[1, 2, 3], &[4, 5, 6]];

        let string1 = String::from("hello");
        let string2 = "hello";
        let string3: String = "hello".into();

        let tuple1 = (1, 2, 3);
        let tuple2 = &(1, 2, 3);
        let tuple3 = (1, "hello", vec![1, 2, 3]);

        let closure1: fn(i32) -> i32 = |x| x + 1;
        let closure2 = |x: i32| x + 1;

        let struct1 = std::io::Error::new(std::io::ErrorKind::Other, "hello");
        let struct2 = TypeAnnotationLrn {};
        let struct3 = &TypeAnnotationLrn {};

        // 如果下文有插入HashMap的值，可以推导出类型，在这里可以不注明类型
        let hashmap1: std::collections::HashMap<i32, String> = std::collections::HashMap::new();
        let mut hashmap2 = std::collections::HashMap::new();
        hashmap2.insert(1, "hello".to_string());
        hashmap2.insert(2, "world".to_string());

        // 指针
        let pointer1: *const f64 = &var2;
        let pointer2: *mut i32 = &mut var1;
    }
}
